#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2010;
struct edge{int u,v,w;edge(int _u,int _v,int _w):u(_u),v(_v),w(_w){}};
bool operator < (edge a,edge b){return a.w > b.w;}
int n,m,fa[N];
char s[N];
vector<int> mem[N];
bitset<N> blo[N];

int gf(int x){return fa[x] ^ x ? fa[x] = gf(fa[x]) : x;}

void solve(){
	n = in,m = in;
	for(int i = 1;i <= n;i++) blo[i].reset();
	for(int i = 1;i <= n;i++) fa[i] = i;
	for(int i = 1;i <= m;i++){
		mem[i].clear();
		scanf("%s",s+1);
		for(int j = 1;j <= n;j++) if(s[j] == '1') blo[j].set(i),mem[i].pb(j);
	}
	vector<pii> G;
	vector<edge> E;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			if(i != j)
				E.pb(edge(i,j,(blo[i] & blo[j]).count()));
	sort(E.begin(),E.end());
	for(edge d : E){
		int x = d.u,y = d.v;
		if(gf(x) != gf(y)){
			fa[gf(x)] = gf(y);
			G.pb(pii(x,y));
		}
	}
	bool ok = 1;
	for(int i = 1;i <= m;i++){
		unsigned int cc = 0;
		for(pii d : G){
			if(blo[d.fi][i] && blo[d.se][i]) cc++;
		}
		if(cc + 1 != mem[i].size()) {ok = 0;break;}
	} 
	if(!ok) puts("NO");
	else{
		puts("YES");
		for(pii d : G){
			printf("%d %d\n",d.fi,d.se);
		}
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	int test = in;
	while(test--) solve();
	return 0;
}

